<?php

//
// +------------------------------------------------------------------------+
// | PHP Version 5.4                                                        |
// +------------------------------------------------------------------------+
// | Copyright (c) All rights reserved.                                     |
// +------------------------------------------------------------------------+
// | 世纪车来车往(北京）网络科技有限公司 版权所有！                           |
// | TEL:010-63732365  HOTLINE:400-6688-365  EMAIL:clcw@clcw.com.cn         |
// | $Revision: 1.0 $                                                       |
// +------------------------------------------------------------------------+
// | Author: xiangminghu@clcw.com.cn                                        |
// +------------------------------------------------------------------------+
//

namespace AuctionBack\Controller;

use \AuctionCore\Other\Equipment as Equipment;
use AuctionCore\System\AuctionException;

/**
 * 设备号管理
 *
 * @author Xmh
 */
class EquipmentController extends BaseController {

    public function __construct() {
        parent::__construct();
        //页面头部信息
        $head = C('HEAD_INDEX');
        $this->assign("web_title", $head['title']);
        $this->assign("web_keywords", $head['keywords']);
        $this->assign("web_description", $head['description']);
        $this->emp_id = $this->user_info['emp_id'];
        
        $this->equipment = new Equipment();

        //模板赋值
        $this->assign("emp_id", $this->emp_id);
    }

    public function index() {
        $this->display();
    }

    /**
     * 获取车源销售列表
     */
    public function equipment_list() {
        $page = I("get.p", 1);
        $size = 10;
        $params = array();
        //获取list
        $result = $this->equipment->equipment_list($page, $size, $params);
        $Page = new \AuctionCore\Common\AjaxPage($result['total'], $size, "get_page");
        $Page->setConfig('theme', " %totalRow% %header% %nowPage%/%totalPage% 页 %first% %upPage% %prePage% %linkPage% %downPage% %nextPage% %end% %jumpform%");
        $show = $Page->show();   // 分页显示输出
        //模板赋值
        $this->assign("p", $page);
        $this->assign('page', $show);   // 赋值分页输出
        $this->assign('list', $result['list']);
        $this->display();
    }
    
    /**
     * 添加设备号
     */
    public function add_equipment(){
        $this->display();
    }
    public function add_equipment_post(){
        $data['imei'] = I('post.imei','','trim');

        $check = $this->equipment->get_equipment_num($data['imei']);
        if($check){
            $this->helpJsonResult(400, '抱歉，该设备号已存在');
        }
        $res = $this->equipment->add_equipment($data);
        if(!$res){
             $this->helpJsonResult(500, '添加失败');
        }
        $this->helpJsonResult(200, '添加成功');
    }
    /**
     * 修改设备号
     */
    public function edit_equipment(){
        $id = I('get.id');
        $equipment = $this->equipment->get_equipment($id);
        $this->assign("equipment",$equipment);
        $this->display();
    }
    
    public function edit_equipment_post(){
        $data['id'] = I('post.id');
        $data['imei'] = I('post.imei','','trim');
        $check = $this->equipment->get_equipment_num($data['imei']);
        if($check){
            $this->helpJsonResult(400, '抱歉，该设备号已存在');
        }
        $res = $this->equipment->save_equipment($data);
        if (!$res) {
            $this->helpJsonResult(500, '修改失败');
        }
        $this->helpJsonResult(200, '修改成功');

    }
}
